import type { ExtractPropTypes } from 'vue'
import type ImportData from './importData.vue'
import { buildProps, definePropType } from '@/utils'

type Download = () => Promise<any> | void
type ImportHttp = (formData: FormData) => Promise<{
  message?: string
  errorUrl?: string
}>

export const importDataProps = buildProps({
  download: {
    type: definePropType<Download>(Function)
  },
  http: {
    type: definePropType<ImportHttp>(Function),
    required: true
  },
  params: {
    type: definePropType<any>(Object)
  },
  // 导出成功、失败都会显示res.data
  showMessage: {
    type: Boolean,
    default: false
  },
  options: {
    type: Array,
    default: () => []
  },
  optionLabel: {
    type: String,
    default: () => ''
  }
} as const)

export const importDataEmits = {
  reload: () => true
}

export type ImportDataProps = ExtractPropTypes<typeof importDataProps>
export type ImportDataEmits = typeof importDataEmits

export type ImportDataInstance = InstanceType<typeof ImportData>

export type ImportDataHttp = ImportDataProps['http']
